﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XWord.WPF.ApplicationFramework.Validations
{
    public class EmptyCollectionValidator : ObjectCollectionValidator
    {
        public override bool Validate()
        {
            ErrorMessage = "列表中存在空值,請檢查";
            if (Collection == null) return false;

            var count = Collection.Cast<object>().Count(e => GetCurrentItemValue(e));
            return count == 0;
        }

        protected override bool GetCurrentItemValue(object item)
        {
            BindingItem(item);
            if (ItemValue == null) return false;
            return string.IsNullOrEmpty(ItemValue.ToString());
        }
    }
}
